﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;

namespace QaaSimulation.QSim.Ships
{
    class QArmorBox : QShipBox
    {
        public QArmorBox()
            : base()
        {
            m_Crew = 0;
            m_Energy = 0;
        }

        public override void Paint(System.Drawing.Graphics g)
        {
            RectangleF rec = new RectangleF(0, 0, QModelBox.BOX_RELATION, QModelBox.BOX_RELATION);
            g.FillRectangle(Brushes.LightGray, rec);

            if (GetNeighbor(QBoxSide.Top) != null && !(GetNeighbor(QBoxSide.Top) is QArmorBox) )
            {
                rec = new RectangleF(0, 0, QModelBox.BOX_RELATION, 0.4f * QModelBox.BOX_RELATION);
                g.FillRectangle(Brushes.DarkGray, rec);
            }

            if (GetNeighbor(QBoxSide.Bottom) != null && !(GetNeighbor(QBoxSide.Bottom) is QArmorBox))
            {
                rec = new RectangleF(0, 0.6f * QModelBox.BOX_RELATION, QModelBox.BOX_RELATION, 0.4f * QModelBox.BOX_RELATION);
                g.FillRectangle(Brushes.DarkGray, rec);
            }

            if (GetNeighbor(QBoxSide.Left) != null && !(GetNeighbor(QBoxSide.Left) is QArmorBox))
            {
                rec = new RectangleF(0, 0, 0.4f * QModelBox.BOX_RELATION, QModelBox.BOX_RELATION);
                g.FillRectangle(Brushes.DarkGray, rec);
            }

            if (GetNeighbor(QBoxSide.Right) != null && !(GetNeighbor(QBoxSide.Right) is QArmorBox))
            {
                rec = new RectangleF(0.6f * QModelBox.BOX_RELATION, 0, 0.4f * QModelBox.BOX_RELATION, QModelBox.BOX_RELATION);
                g.FillRectangle(Brushes.DarkGray, rec);
            }                       
        }

        public override bool CanBePlaced(QShipBox[] neighborhood)
        {
            int neighborCount = 0;
            for (int i = 0; i < 4; i++)
                if (neighborhood[i] != null)
                    neighborCount++;

            return neighborCount < 4;
        }
    }
}
